package br.org.credfaz.sis.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import br.org.credfaz.sis.Db2ConnectionFactory;
import br.org.credfaz.sis.modelo.Cliente;
import br.org.credfaz.sis.modelo.TceCliente;

public class TceClienteDAO {
	private final Connection connection;
	
	public TceClienteDAO(){
		try{
			connection = new Db2ConnectionFactory()
								.getConnection();
		}catch (SQLException e){
			throw new RuntimeException(e);
		}
	}
	
	public List<TceCliente> lista(){
		try{
			List<TceCliente> dbcliente = new ArrayList<TceCliente>();
			PreparedStatement stmt = this.connection.prepareStatement("select idcliente, numcpfcnpj, nomereceita from coopcons.CLIENTE ");
			//"select cl.idcliente, cl.numcpfcnpj, cl.nomereceita from coopcons.CLIENTE cl, coopcons.contacapital ca " +
			//"where cl.idcliente = ca.idcliente and ca.codtiposituacaoassociado = 1"
			ResultSet rs = stmt.executeQuery();
			
			while(rs.next()){
				dbcliente.add(populaDbCliente(rs));
			}
			
			rs.close();
			
			return null;
		}catch (SQLException e){
			throw new RuntimeException(e);
		}
	}
		
	ClienteDAO addcliente = new ClienteDAO();
	
	private TceCliente populaDbCliente(ResultSet rs) throws SQLException {
		Cliente cliente = new Cliente();
		
		cliente.setIdcliente(rs.getLong("idcliente"));
		cliente.setNumcpfcnpj(rs.getString("numcpfcnpj"));
		cliente.setNomereceita(rs.getString("nomereceita"));
		
		addcliente.adiciona(cliente);
		return null;
	}

	

}
